package com.alvin.mbp.service;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.alvin.mbp.dao.BaseDao;
import com.alvin.mbp.entity.BaseEntity;

/**
 * service基类.
 * 
 * 
 * 
 * @param <T>
 *            实体类类型
 */
@Transactional
public abstract class BaseService<T extends BaseEntity> {
	protected BaseDao<T> baseDao;

	public BaseDao<T> getBaseDao() {
		return baseDao;
	}

	public abstract void setBaseDao(BaseDao<T> baseDao);

	@Transactional(readOnly = true)
	public List<T> findAll() {
		return baseDao.findAll();
	}
	
	@Transactional(readOnly = true)
	public List<T> findAll(int topNum) {
		return baseDao.findAll(topNum);
	}

	@Transactional(readOnly = true)
	public List<T> findByProperty(String property, Object value) {
		return baseDao.findByProperty(property, value);
	}
	
	@Transactional(readOnly = true)
	public List<T> findByProperty(String property, Object value,int topNum) {
		return baseDao.findByProperty(property, value, topNum);
	}

	@Transactional(readOnly = true)
	public T findByPropertyOne(String property, Object value) {
		return baseDao.findByPropertyOne(property, value);
	}

	@Transactional
	public void updateByID(Integer id, String property, Object value) {
		baseDao.updateByID(id, property, value);
	}

	@Transactional
	public T findById(Integer id) {
		return baseDao.findById(id);
	}

	@Transactional(readOnly = true)
	public List<T> findBySql(String sql, Object[] params) {
		return baseDao.findBySql(sql, params);
	}

	@Transactional
	public void update(T entity) {
		baseDao.update(entity);
	}

	@Transactional
	public void save(T entity) {
		baseDao.save(entity);
	}

}
